package top.oylan.manager.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.oylan.manager.entity.Banner;
import top.oylan.manager.entity.Product;
import top.oylan.manager.entity.api.HomeApi;
import top.oylan.manager.entity.api.entity.BannerEntity;
import top.oylan.manager.entity.api.result.HomeResult;
import top.oylan.manager.entity.api.entity.ProductEntity;
import top.oylan.manager.service.BannerService;
import top.oylan.manager.service.ProductService;
import top.oylan.manager.tools.ApiUtils;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/api/home")
@Api(value = "home", description = "首页接口", produces = MediaType.APPLICATION_JSON_VALUE)
public class ApiIndexController {

    @Resource
    BannerService bannerService;

    @Resource
    ProductService productService;

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    @ApiOperation(value = "首页",response = HomeApi.class,httpMethod = "GET")
    public HomeApi index(){

        HomeApi api = new HomeApi();

        HomeResult entity = new HomeResult();

        ArrayList<Banner> banners = bannerService.selectBannerByPosition(1);
        List<BannerEntity> bannerEntities = (List<BannerEntity>)banners.clone();
        entity.setBanners(bannerEntities);

        ArrayList<Product> notes = productService.selectByType(4);
        List<ProductEntity> productEntities = (List<ProductEntity>)notes.clone();
        entity.setNotes(productEntities);

        ArrayList<Product> course = productService.selectByType(1);
        List<ProductEntity> courseEntities = (List<ProductEntity>)course.clone();
        entity.setCourse(courseEntities);

        ArrayList<Product> film = productService.selectByType(2);
        List<ProductEntity> filmEntities  = (List<ProductEntity>)film.clone();
        entity.setFilm(filmEntities);

        ArrayList<Product> movies = productService.selectByType(3);
        List<ProductEntity> movieEntities = (List<ProductEntity>)movies.clone();
        entity.setMovie(movieEntities);

        ApiUtils.addRightData(api,"请求成功",entity);

        return api;
    }

}
